﻿using OOAD_PROJEKAT;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace Main_application
{
    /// <summary>
    /// Interaction logic for promjena.xaml
    /// </summary>
    public partial class promjenaZ : Window
    {
        public Zaposlenik novina;
        public promjenaZ(Zaposlenik kaka)
        {
            InitializeComponent();
            ime.BorderBrush = SystemColors.ControlDarkBrush;
            ime1.BorderBrush = SystemColors.ControlDarkBrush;
            novina = kaka;
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            if (String.IsNullOrEmpty(ime.Text))
            {
                ime.BorderBrush = Brushes.Red;
                ime.ToolTip = "Morate izrabrati atribut!";
            }
            else
            {
                ime.BorderBrush = SystemColors.ControlDarkBrush;
                ime.ToolTip = null;
                if (String.IsNullOrEmpty(ime1.Text))
                {
                    ime1.BorderBrush = Brushes.Red;
                    ime1.ToolTip = "Morate unijeti vrijednost!";
                }
                else
                {
                    ime1.BorderBrush = SystemColors.ControlDarkBrush;
                    ime1.ToolTip = null;
                    switch (ime.Text)
                    {
                        case "Ime":
                            novina.Ime = ime1.Text;
                            break;
                        case "Prezime":
                            novina.Prezime = ime1.Text;
                            break;
                        case "JMBG":
                            novina.Jmbg = ime1.Text;
                            break;
                        case "Username":
                            novina.Username = ime1.Text;
                            break;
                        case "Password":
                            novina.Password = ime1.Text;
                            break;
                        case "Filijala":

                            DAL.DAL.FilijalaDAO klijeD = new DAL.DAL.FilijalaDAO();
                            List<Filijala> f = klijeD.getAll();
                            bool nasao = false;
                            foreach(Filijala x in f)
                            {
                                if(x.Id == Convert.ToInt32(ime1.Text))
                                    nasao = true;

                            }
                            if (nasao)
                            {
                                novina.IdFilijale = Convert.ToInt32(ime1.Text);
                            }
                            else global::System.Windows.MessageBox.Show("Ne postoji filijala");
                            break;
                    }
                    try
                    {
                        if (novina is ITSektorRadnik)
                        {

                            DAL.DAL.ITSektorRadnikDAO kl = new DAL.DAL.ITSektorRadnikDAO();
                            kl.update(novina as ITSektorRadnik);
                        }
                        else if (novina is Preuzimac)
                        {

                            DAL.DAL.PreuzimacDAO kl = new DAL.DAL.PreuzimacDAO();
                            kl.update(novina as Preuzimac);
                        }
                        else if (novina is OZaposlenik)
                        {

                            DAL.DAL.OZaposlenikDAO kl = new DAL.DAL.OZaposlenikDAO();
                            kl.update(novina as OZaposlenik);
                        }
                        else if (novina is EFSRadnik)
                        {

                            DAL.DAL.EFSRadnikDAO kl = new DAL.DAL.EFSRadnikDAO();
                            kl.update(novina as EFSRadnik);
                        }
                        
                    }
                    catch (Exception la)
                    {
                        MessageBox.Show(la.Message);
                    }
                }
            }
        }
    }
}
